package com.duyj.server.account.service.impl;

import com.duyj.client.account.model.Account;
import com.duyj.server.account.dao.AccountDAO;
import com.duyj.server.account.service.AccountService;
import io.seata.core.context.RootContext;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

@Service
public class AccountServiceImpl implements AccountService {

    private static final Logger logger = org.slf4j.LoggerFactory.getLogger(AccountServiceImpl.class);


    @Autowired
    private AccountDAO accountDAO;

    @Override
    @Transactional
    public void updateAccount(Account account) {
        logger.info("Service Begin ... xid: " + RootContext.getXID());
        accountDAO.updateAccount(account);
    }

    @Override
    @Transactional
    public void putAccount(String name) {
        logger.info("Service Begin ... xid: " + RootContext.getXID());
        if (name == null) {
            throw new RuntimeException("name is null");
        }
        accountDAO.insertAccount(new Account(name, BigDecimal.valueOf(1000L)));
    }
}
